package com.sample.tdf.sample.api;

import cn.com.taiji.common.dto.ResultDTO;
import cn.com.taiji.common.exception.BaseException;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.sample.tdf.sample.dto.StudentDTO;
import com.sample.tdf.sample.service.IStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 太极计算机股份有限公司
 * @since 2020-04-07
 */
@Api(tags = "学生接口")
@RestController
@RequestMapping("/sample/student")
public class StudentController  {

    @Autowired
    private IStudentService iStudentService;


    @ApiOperation(value = "根据studentClass查询")
    @GetMapping(value = "/findByStudentClass")
    public ResultDTO findByStudentClass(@RequestParam String studentClass) {
        return null;
    }



    @ApiOperation(value = "动态sql示例")
    @GetMapping(value = "/dynamicsql")
    public ResultDTO dynamicSql() {
        return null;
    }


    @Valid
    @ApiOperation("1.新增")
    @ApiOperationSupport(order = 1)
    @PostMapping
    public ResultDTO<StudentDTO> create(@RequestBody StudentDTO dto) throws BaseException {
        StudentDTO studentDTO = iStudentService.create(dto);
        return new ResultDTO(studentDTO);
    }

    @Valid
    @ApiOperation("1.修改")
    @ApiOperationSupport(order = 1)
    @PutMapping
    public ResultDTO<StudentDTO> update(@RequestBody StudentDTO dto) throws BaseException {
        StudentDTO update = iStudentService.update(dto);
        return new ResultDTO(update);
    }

    @Valid
    @ApiOperation("1.嵌套一对多一次查询")
    @ApiOperationSupport(order = 1)
    @GetMapping({"/{id}"})
    public ResultDTO<StudentDTO> findByIdOneSelect(@PathVariable("id") String id) throws BaseException {
        StudentDTO update = iStudentService.findByIdOneSelect(id);
        return new ResultDTO(update);
    }

    @Valid
    @ApiOperation("1.嵌套一对多两次查询")
    @ApiOperationSupport(order = 1)
    @GetMapping({"/findByIdTwoSelect"})
    public ResultDTO<StudentDTO> findByIdTwoSelect(String id) throws BaseException {
        StudentDTO update = iStudentService.findByIdTwoSelect(id);
        return new ResultDTO(update);
    }

}

